home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.5 KB | 270 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPictSv.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPICTSV_H
- #include "FWPictSv.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //========================================================================================
- // CLASS FW_CPictSView
- //========================================================================================
-
- //FW_DEFINE_CLASS_M1(FW_CPictSView, FW_CSuperView)
- FW_DEFINE_AUTO(FW_CPictSView)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::FW_CPictSView
- //----------------------------------------------------------------------------------------
-
- FW_CPictSView::FW_CPictSView (Environment *ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- FW_CPicture& picture,
- FW_EScrollingDirection scrollDir) :
- FW_CSuperView(ev, container, bounds, viewID, FW_kZeroPoint, scrollDir),
- fPicture(picture),
- fPictID(0),
- fPictNotFound(false)
- {
- // Adjust the view extent to the size of the picture
- FW_CRect rect;
- picture.GetPictBounds(rect);
- SetExtent(ev, rect.Size());
-
- // Overrides FW_CSuperView default bindings to keep fixed bounds
- SetBindings(ev, FW_kFixedBounds);
- // SetResizeForceRedraw(ev, true);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::FW_CPictSView
- //----------------------------------------------------------------------------------------
-
- FW_CPictSView::FW_CPictSView (Environment *ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- FW_ResourceID pictID,
- const FW_CPoint& extent,
- FW_EScrollingDirection scrollDir) :
- FW_CSuperView(ev, container, bounds, viewID, FW_kZeroPoint, scrollDir),
- fPictID(pictID),
- fPictNotFound(false)
- {
- Initialize(ev, extent);
-
- // Overrides FW_CSuperView default bindings to keep fixed bounds
- SetBindings(ev, FW_kFixedBounds);
- // SetResizeForceRedraw(ev, true);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::FW_CPictSView
- //----------------------------------------------------------------------------------------
-
- FW_CPictSView::FW_CPictSView(Environment* ev) :
- FW_CSuperView(ev),
- fPictID(0),
- fPictNotFound(false)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::~FW_CPictSView
- //----------------------------------------------------------------------------------------
-
- FW_CPictSView::~FW_CPictSView()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPictSView::Initialize(Environment* ev, const FW_CPoint& extent)
- {
- FW_TRY
- {
- // Load the picture from the part shared library
- FW_PSharedLibraryResourceFile resFile(ev);
- fPicture = FW_CPicture(resFile, fPictID);
-
- // By default we adjust the view extent to the size of the picture
- if (extent == FW_kZeroPoint)
- {
- FW_CRect rect;
- fPicture.GetPictBounds(rect);
- SetExtent(ev, rect.Size());
- }
- else
- {
- SetExtent(ev, extent);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, except)
- {
- fPictNotFound = true;
- SetExtent(ev, GetBounds(ev).Size());
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::DrawPictNotFound
- //----------------------------------------------------------------------------------------
-
- void FW_CPictSView::DrawPictNotFound(Environment* ev, FW_CViewContext& vc, FW_Boolean usePictID)
- {
- // Draw a pink rectangle
- FW_CRect viewRect(FW_kZeroPoint, GetExtent(ev));
- FW_CRectShape::RenderRect(vc, viewRect, FW_kFill, FW_CColor(255, 204, 204),
- FW_CStyle(FW_kFixedPos1, FW_kGrayPat));
-
- FW_CString text;
- if (usePictID)
- {
- // Write the classID in the middle
- FW_CString idstr;
- idstr.ReplaceAllAsSignedDecimalInteger(fPictID);
- text += "PICT ID ";
- text += idstr;
- text += " not found!";
- }
- else
- text += "Picture not found!";
-
- FW_CTextBoxShape::RenderTextBox(vc, text, viewRect,
- FW_CFont(FW_GetDefaultFontName(), FW_kBold, FW_IntToFixed(10)), 0);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CPictSView::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, facet, invalidShape);
-
- if (fPictNotFound)
- {
- DrawPictNotFound(ev, vc, true);
- }
- else
- {
- // Erase with white first
- FW_CRect invalidRect;
- vc.GetClipRect(invalidRect);
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- FW_CRect rect(FW_kZeroPoint, GetExtent(ev));
- FW_CPictureShape::RenderPicture(vc, fPicture, rect);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::DrawAnotherPicture
- //----------------------------------------------------------------------------------------
-
- void FW_CPictSView::DrawAnotherPicture(Environment* ev, ODFacet* facet, ODShape* invalidShape,
- FW_CPicture& picture, FW_Boolean scale)
- {
- // This is the same as Draw, but using another picture
-
- FW_CViewContext vc(ev, this, facet, invalidShape);
-
- // Erase with white first
- FW_CRect invalidRect;
- vc.GetClipRect(invalidRect);
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- if (picture)
- {
- FW_CRect rect;
- if (scale)
- rect = FW_CRect(FW_kZeroPoint, GetExtent(ev));
- else
- picture.GetPictBounds(rect);
-
- FW_CPictureShape::RenderPicture(vc, picture, rect);
- }
- else
- {
- #ifdef FW_DEBUG
- DrawPictNotFound(ev, vc, false);
- #endif
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPictSView::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CSuperView::Flatten(ev, stream);
-
- stream << fPictID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictSView::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CPictSView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CSuperView::InitializeFromStream(ev, stream);
-
- stream >> fPictID;
-
- Initialize(ev, FW_kZeroPoint);
- }
-
-